//
//  NavigetionViewDetail.swift
//  NaiCha
//
//  Created by 唐安坤 on 2024/9/10.
//

import SwiftUI

struct NavigetionViewDetail: View {
    @EnvironmentObject var settingStore: SettingStore
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
    var model: MyDogModel
    @State var isShowAlert = false
    var body: some View {
        NavigationStack {
            ScrollView {
                VStack(spacing:20){
                    MyDogCardView(image: model.image, name: model.dogName)
                    HStack{
                        VStack(alignment:.leading){
                            Text(model.dogName).font(.system(size: 30,weight: .bold)).padding(.bottom)
                            Text("生日：2021年9月11日").font(.system(size: 14)).foregroundStyle(.gray)
                                .padding(EdgeInsets(top: 0, leading: 0, bottom: 2, trailing: 0))
                            Text("发布：13小时前").font(.system(size: 14)).foregroundStyle(.gray)
                        }
                        Spacer()
                        Image(model.image, bundle: nil)
                            .resizable()
                            .aspectRatio(contentMode: .fill)
                            .frame(width: 100,height: 100)
                            .clipShape(RoundedRectangle(cornerRadius: 5))
                        
                    }
                    .padding(EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10))
                    .background(.purple.opacity(0.1))
                    .clipShape(RoundedRectangle(cornerRadius: 10))
                    
                    if settingStore.toogle{
                        VStack(){
                            HStack{
                                Text(model.dogName).font(.system(size: 30,weight: .bold)).padding(EdgeInsets(top: 0, leading: 0, bottom: 3, trailing: 0))
                                Spacer()
                            }
                            HStack{
                                Text("狗分布于世界各地。狗爱吃肉，也吃狗饲料和人类的饭菜、水果、零食等。狗不会流汗，以张嘴巴、吐舌头排放体内的热气 [16]。狗为季节性单次发情动物，一年内在春季3-5月和秋季9-11月发情，野狗在1-2月时发情，发情期为6-14天 [17]。狗的孕期通常为3个月 [18]，有时一次能够生下十到十二只小狗幼崽；体型较小的品种则每次最多只能生下四五只小狗，一般它们一胎产下一两只幼崽是更为常见的情况 [19]。狗的寿命相对较短，一般为12年左右").font(.system(size: 14)).foregroundStyle(.gray)
                                Spacer()
                            }
                        }
                    }
                    
                }.padding()
            }.navigationTitle(model.dogName)
                .navigationBarTitleDisplayMode(.inline)
                .navigationBarBackButtonHidden(true)
                .toolbar{
                    ToolbarItem(placement: .topBarLeading) {
                        Button(action: {
                            //presentationMode.wrappedValue.dismiss()
                            isShowAlert = true
                        }, label: {
                            Image(systemName: "xmark.circle.fill").foregroundColor(.gray)
                        }).alert(isPresented: $isShowAlert, content: {
                            Alert(title: Text("确定关闭"), message: Text("关闭了你还来吗"), primaryButton: Alert.Button.cancel(Text("取消"), action: {
                                
                            }), secondaryButton: Alert.Button.destructive(Text("关闭"), action: {
                                presentationMode.wrappedValue.dismiss()
                            }))
                        })
                    }
                }
        }
    }
}

#Preview {
    NavigetionViewDetail(model: MyDogModel.init(image: "dog01", dogName: "dog"))
}
